﻿/* Copyright (c) 2010 EPiServer AB
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
using System.Web.UI.WebControls;
using EPiServer.Core;
using EPiServer.Web.PropertyControls;

namespace EPiServer.Municipality.Web.UI.PropertyControls {
    /// <summary>
    /// PropertyControl implementation used for rendering PropertyReviewed.cs data.
    /// </summary>
    public class PropertyReviewedControl : PropertyDataControl {

        private CheckBox _cb;

        /* *******************************************************************
         * Properties
         * *******************************************************************/
        #region public PropertyReviewed PropertyReviewed
        /// <summary>
        /// Gets the PropertyReviewed instance for this IPropertyControl.
        /// </summary>
        /// <value>The property that is to be displayed or edited.</value>
        public PropertyReviewed PropertyReviewed {
            get {
                return PropertyData as PropertyReviewed;
            }
        }
        #endregion
        #region public DateTime Date
        /// <summary>
        /// Get/Sets the Date of the PropertyReviewedControl
        /// </summary>
        /// <value></value>
        public DateTime Date {
            get {
                return ((PropertyDate)PropertyData).Date;
            }
            set {
                ((PropertyDate)PropertyData).Date = value;
            }
        }
        #endregion
        /* *******************************************************************
         *  Methods
         * *******************************************************************/
        #region public override void CreateEditControls()
        /// <summary>
        /// 
        /// </summary>
        public override void CreateEditControls() {
            _cb = new CheckBox();
            _cb.ID = Name;
            Controls.Add(_cb);
        }
        #endregion
        #region public override void ApplyEditChanges()
        /// <summary>
        /// 
        /// </summary>
        public override void ApplyEditChanges() {
            if (_cb.Checked)
                SetValue(DateTime.Now);
            else if (PropertyData.Value == null)
                SetValue(((PageBase)Page).CurrentPage.Created);
        }
        #endregion
    }
}